package com.qilu.pe.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.makeramen.roundedimageview.RoundedImageView;
import com.qilu.pe.R;
import com.qilu.pe.base.Config;
import com.qilu.pe.dao.bean.ItemSetDetail;
import com.qilu.pe.support.util.GlideUtil;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class ItemSetDetail2Fragment extends Fragment {
    private TextView tv_other;
    private RecyclerView rcv_sample;

    private SampleListAdapter adapter;
    private List<ItemSetDetail.SubInfo> subInfoList = new ArrayList<>();

    private ItemSetDetail detail;

    public ItemSetDetail2Fragment() {

    }

    public static ItemSetDetail2Fragment newInstance(String param1, ItemSetDetail detail) {
        ItemSetDetail2Fragment fragment = new ItemSetDetail2Fragment();
        Bundle args = new Bundle();
        args.putSerializable("detail", detail);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        detail = (ItemSetDetail) getArguments().getSerializable("detail");
        adapter = new SampleListAdapter(getActivity());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_item_set_detail2, container, false);
        rcv_sample = v.findViewById(R.id.rcv_sample);
        tv_other = v.findViewById(R.id.tv_other);

        tv_other.setText(detail.getRemark());

        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        rcv_sample.setLayoutManager(manager);
        rcv_sample.setAdapter(adapter);

        subInfoList.add(detail.getSubinfo());
        adapter.setDataList(subInfoList);

        return v;
    }

    private class SampleListAdapter extends ListBaseAdapter<ItemSetDetail.SubInfo> {

        public SampleListAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_item_detail_2_sample_and_consume_list;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            TextView tv_consume = holder.getView(R.id.tv_consume);
            TextView tv_num = holder.getView(R.id.tv_num);
            TextView tv_name1 = holder.getView(R.id.tv_name1);
            TextView tv_name2 = holder.getView(R.id.tv_name2);
            TextView tv_name3 = holder.getView(R.id.tv_name3);
            TextView tv_hint = holder.getView(R.id.tv_hint);
            TextView tv_hint_info = holder.getView(R.id.tv_hint_info);
            RoundedImageView iv_sample_img = holder.getView(R.id.iv_sample_img);

            ItemSetDetail.SubInfo consume = mDataList.get(position);

            tv_consume.setText(consume.getName());
            tv_num.setText("×" + consume.getCount());
            tv_name1.setText("血清");// consume.getSample()
            tv_name2.setText(TextUtils.equals("1", consume.getType()) ? "常温" : "冷藏");
            tv_name3.setText(consume.getCapacity());
            tv_hint.setText(consume.getSampling());
            tv_hint_info.setText(consume.getNotice());
            GlideUtil.loadImg(Config.URL_IMG + consume.getPicture(), iv_sample_img);
        }
    }
}